

create   trigger [dbo].[tb_posexchprizedtl_ai] on [dbo].[tb_posexchprizedtl] for insert
 as 
 declare  @depotid int,
          @productid int, 
          @bquantity decimal(22,8),
          @custom1 varchar(100),@custom2 varchar(100),@custom3 varchar(100),
          @length decimal(22,8),@width decimal(22,8),@height decimal(22,8),
          @braiserror int
 begin
   set nocount on
   set  @braiserror = 0

   declare tb_posexchprizedtl_cr cursor local forward_only static optimistic for
   select productid,bquantity,m.depotid,d.custom1,d.custom2,d.custom3,d.length,d.width,d.height 
     from inserted d left join tb_posexchprize m on m.bid = d.bid
     open tb_posexchprizedtl_cr 
     fetch next from tb_posexchprizedtl_cr into @productid,@bquantity,@depotid
     ,@custom1,@custom2,@custom3,@length,@width,@height
     while @@fetch_status =0
     begin
       exec p_updateusedqty @depotid, @productid, @bquantity, @custom1, @custom2, @custom3, @length, @width, @height         
       fetch next from tb_posexchprizedtl_cr into @productid,@bquantity,@depotid
       ,@custom1,@custom2,@custom3,@length,@width,@height
     end
   close tb_posexchprizedtl_cr
   deallocate tb_posexchprizedtl_cr
   if (@braiserror =1)
    return
 end






GO


